﻿// ===============================================================================
//  Copyright © ymind.net. All rights reserved .
//  官方网站：http://ymind.net/
//  版权所有：彦铭工作室 老陈出品
// ===============================================================================

using System;
using Lcsoft.RssEngine.Collections;
using Lcsoft.RssEngine.Shared;

namespace Lcsoft.RssEngine
{
	/// <summary>A module may contain any number of items (either channel-based or item-based).</summary>
	[Serializable]
	public class RssModuleItem : IRssElement
	{
		private string _sElementName = String.Empty;
		private string _sElementText = String.Empty;

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		public RssModuleItem() { this.SubElements = new RssModuleItemCollection(); }

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		public RssModuleItem(string name)
		{
			this.SubElements = new RssModuleItemCollection();
			this._sElementName = RssDefault.Check(name);
		}

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		/// <param name="required">Is text required for this RssModuleItem?</param>
		public RssModuleItem(string name, bool required) : this(name) { this.IsRequired = required; }

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		/// <param name="text">The text contained within this RssModuleItem.</param>
		public RssModuleItem(string name, string text) : this(name) { this._sElementText = RssDefault.Check(text); }

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		/// <param name="required">Is text required for this RssModuleItem?</param>
		/// <param name="text">The text contained within this RssModuleItem.</param>
		public RssModuleItem(string name, bool required, string text) : this(name, required) { this._sElementText = RssDefault.Check(text); }

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		/// <param name="text">The text contained within this RssModuleItem.</param>
		/// <param name="subElements">The sub-elements of this RssModuleItem (if any exist).</param>
		public RssModuleItem(string name, string text, RssModuleItemCollection subElements) : this(name, text) { this.SubElements = subElements; }

		/// <summary>Initialize a new instance of the RssModuleItem class</summary>
		/// <param name="name">The name of this RssModuleItem.</param>
		/// <param name="required">Is text required for this RssModuleItem?</param>
		/// <param name="text">The text contained within this RssModuleItem.</param>
		/// <param name="subElements">The sub-elements of this RssModuleItem (if any exist).</param>
		public RssModuleItem(string name, bool required, string text, RssModuleItemCollection subElements) : this(name, required, text) { this.SubElements = subElements; }

		/// <summary>
		/// The name of this RssModuleItem.
		/// </summary>
		public string Name
		{
			get { return this._sElementName; }
			set { this._sElementName = RssDefault.Check(value); }
		}

		/// <summary>
		/// The text contained within this RssModuleItem.
		/// </summary>
		public string Text
		{
			get { return this._sElementText; }
			set { this._sElementText = RssDefault.Check(value); }
		}

		/// <summary>
		/// The sub-elements of this RssModuleItem (if any exist).
		/// </summary>
		public RssModuleItemCollection SubElements { get; set; }

		/// <summary>
		/// Is text for this element required?
		/// </summary>
		public bool IsRequired { get; private set; }

		/// <summary>Returns a string representation of the current Object.</summary>
		/// <returns>The item's title, description, or "RssModuleItem" if the title and description are blank.</returns>
		public override string ToString() { return this._sElementName ?? (this._sElementText ?? "RssModuleItem"); }
	}
}
